package main

import (
	"fmt"
	"math/rand"
	"sort"
)

type Usb interface {
	Start()
	Stop()
}
type Phone struct {
}

func (p Phone) Start() {
	fmt.Println("手机开始工作")
}
func (p Phone) Stop() {
	fmt.Println("手机停止工作")
}

type Camera struct {
}

func (c Camera) Start() {
	fmt.Println("相机开始工作")
}
func (c Camera) Stop() {
	fmt.Println("相机停止工作")
}

type Computer struct {
}

func (c Computer) Working(usb Usb) {
	usb.Start()
	usb.Stop()
}

type Hero struct {
	Name string
	Age  int
}
type HeroSlice []Hero

func (hs HeroSlice) Len() int {
	return len(hs)
}
func (hs HeroSlice) Less(i, j int) bool {
	return hs[i].Age > hs[j].Age
}
func (hs HeroSlice) Swap(i, j int) {
	temp := hs[i]
	hs[i] = hs[j]
	hs[j] = temp
	//hs[i],hs[j] = hs[j],hs[i]
}

type Arr []int

func (arr Arr) Len() int {
	return len(arr)
}
func (arr Arr) Less(i, j int) bool {
	return arr[i] < arr[j]
}
func (arr Arr) Swap(i, j int) {
	arr[i], arr[j] = arr[j], arr[i]
}
func main() {
	camera := Camera{}
	phone := Phone{}
	computer := Computer{}
	computer.Working(camera)
	computer.Working(phone)
	var heros HeroSlice
	for i := 0; i < 10; i++ {
		hero := Hero{
			Name: fmt.Sprintf("英雄~%d", rand.Intn(100)),
			Age:  rand.Intn(100),
		}
		heros = append(heros, hero)
	}
	for _, val := range heros {
		fmt.Println(val)
	}
	sort.Sort(heros)
	fmt.Println("-------------------------------------")
	for _, val := range heros {
		fmt.Println(val)
	}
	var arr Arr = []int{3, 2, 5, 7, 1, 9}
	sort.Ints(arr)
	sort.Reverse(arr)
	fmt.Println(arr)
}
